package com.tbit.uqbike.service.business.operationsanalysis.impl;

import com.tbit.common.entity.pojo.dto.ReturnBikeMsgLogDTO;
import com.tbit.common.entity.pojo.vo.ParkPointCoreDataVO;
import com.tbit.common.entity.pojo.vo.ReturnBikeMsgLogVO;
import com.tbit.uqbike.constant.MapConstant;
import com.tbit.uqbike.object.business.Point;
import com.tbit.uqbike.service.base.CalibrateService;
import com.tbit.uqbike.service.business.operationsanalysis.ParkPointOAService;
import com.tbit.uqbike.webmanager.dao.core.ParkPointDao;
import com.tbit.uqbike.webmanager.dao.log.ReturnBikeMsgLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 站点分析Service接口实现
 *
 * @author <a href="mailto:chen.wutian@tbit.com.cn">BUGTian</a>
 * @since 2025/2/27
 */
@Service
public class ParkPointOAServiceImpl implements ParkPointOAService {

    @Resource
    private ParkPointDao parkPointDao;
    @Autowired
    private CalibrateService calibrateService;
    @Autowired
    private ReturnBikeMsgLogDao returnBikeMsgLogDao;

    @Override
    public ParkPointCoreDataVO getCoreData(Integer accountId, Date startTime, Date endTime) {
        ParkPointCoreDataVO coreData = parkPointDao.getCoreData(accountId);
        Integer productNum = parkPointDao.getParkPointReturnData(accountId, startTime, endTime);
        coreData.setProductNum(productNum);
        coreData.setNotProductNum(coreData.getParkPointCount() - productNum);
        return coreData;
    }

    @Override
    public List<ReturnBikeMsgLogVO> getApplyReturnBikePoint(ReturnBikeMsgLogDTO returnBikeMsgLogDTO) {
        List<ReturnBikeMsgLogVO> returnBikePoint = returnBikeMsgLogDao.getApplyReturnBikePoint(returnBikeMsgLogDTO);
        for (ReturnBikeMsgLogVO returnBikeMsgLogVo : returnBikePoint) {
            if (returnBikeMsgLogVo.getLon() != null && returnBikeMsgLogVo.getLat() != null) {
                Point point = calibrateService.calibrateOffSet(returnBikeMsgLogVo.getLon(), returnBikeMsgLogVo.getLat(),
                        MapConstant.MAP_GOOGLE);
                returnBikeMsgLogVo.setLonC(point.getX());
                returnBikeMsgLogVo.setLatC(point.getY());
            }
        }
        return returnBikePoint;
    }
}
